#pragma once
#include <nice2d/sprite.h>
#include <nice2d/textoption.h>
#include <nice2d/imageset.h>

class Piece : public Sprite
{
    DECLARE_OBJECT(Piece)
public:
    Piece() = delete;
    Piece(const TextOption& option,const std::wstring &name = std::wstring());
    virtual ~Piece();
public:
    void setPieceType(int32_t type);
    int getPieceType()const;

    void setHitPoint(uint32_t value);
    uint32_t getHitPoint()const;

    bool isDeath()const;

    void setAttack(uint32_t value);
    uint32_t getAttack()const;

    void setDefense(uint32_t value);
    uint32_t getDefence()const;

    void setMovement(uint32_t value);
    uint32_t getMovement()const;
public:
    void addPieceIcon(const std::string& file,const sf::IntRect& area = {});
    void setPieceIcons(std::shared_ptr<ImageSet> set);

    void setTextColor(const sf::Color& color);
    sf::Color getTextColor()const;

    void setName(const std::wstring &name);
    std::wstring getName()const;

    void setDescription(const std::wstring &description);
    std::wstring getDescription()const;

    void configurate();
    bool isConfigurated()const;

    void setConfiguratedTile(std::shared_ptr<Tile> tile);
    std::weak_ptr<Tile> getConfiguratedTile();
public:
    virtual PTree serialize() override;
    virtual void deserialize(const PTree &node) override;

    void onUpdateSprite(float deltaTime) override;
    void onDrawSprite(sf::RenderTarget &target, sf::RenderStates states) const override;

    void onSpriteColorChanged()override;
    virtual void onPositionChanged() override;
    virtual void onSizeChanged() override;
    virtual void onRotateChanged() override;
    virtual void onScaleChanged() override;
private:
    std::unique_ptr<class PieceData> data;
};
